﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BLL;

public partial class admin_Report : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        LoadCategory();

        if (Request.QueryString["cate"] != null)
        {
          dropParent.SelectedValue = Request.QueryString["cate"];
          linkProductHot.NavigateUrl = "~/admin/Report/ProductHot.aspx?cate=" + dropParent.SelectedValue;
          linkProductVote.NavigateUrl = "~/admin/Report/ProductVote.aspx?cate=" + dropParent.SelectedValue;
          linkProductBuy.NavigateUrl = "~/admin/Report/ProductOrder.aspx?cate=" + dropParent.SelectedValue;

        }
      }
    }
    ProdCateBLL categoryData = new ProdCateBLL();

    private void ShowChild(int parentId, string space)
    {
      List<ProdCate> listDataSource = categoryData.GetByParent(parentId);

      foreach (ProdCate item in listDataSource)
      {
        ListItem obj = new ListItem(space + item.Name, item.Id.ToString());
        dropParent.Items.Add(obj);

        ShowChild(item.Id, space + "- - - ");
      }
    }
    private void LoadCategory()
    {
      dropParent.Items.Clear();
      ShowChild(0, " - - ");
      ListItem itemRoot = new ListItem("Danh mục gốc", "0");
      dropParent.Items.Insert(0, itemRoot);

      ListItem itemNull = new ListItem("Tất cả", "-1");
      dropParent.Items.Insert(0, itemNull);
    }
    protected void dropParent_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (Request.QueryString["cate"] != null)
      {
        string url = Request.RawUrl.Replace("cate=" + Request.QueryString["cate"], "cate=" + dropParent.SelectedValue);
        
        
        Response.Redirect(url);
      }
      else
      {
        linkProductHot.NavigateUrl = "~/admin/Report/ProductHot.aspx?cate=" + dropParent.SelectedValue;
        linkProductVote.NavigateUrl = "~/admin/Report/ProductVote.aspx?cate=" + dropParent.SelectedValue;
        linkProductBuy.NavigateUrl = "~/admin/Report/ProductOrder.aspx?cate=" + dropParent.SelectedValue;
      }
    }
}